package middleware

import (
	"gin_chat_demo/config/zap"
	"github.com/gin-gonic/gin"
	"net/http"
)

func RecoverMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				// 记录错误信息
				zap.Logger.Errorf("panic occurred: %v\n", err)
				// 返回错误响应
				c.AbortWithStatus(http.StatusInternalServerError)
			}
		}()
		c.Next()
	}
}
